# -*- coding: utf-8 -*-
from django.utils.safestring import mark_safe
from django import forms
from django.forms.widgets import RadioSelect

__author__ = 'Junior Lima'

from evento.models import Evento, Pessoa, InscricaoEvento, SEXO_CHOICES


class HorizRadioRenderer(forms.RadioSelect.renderer):
    def render(self):
        return mark_safe(u'\n'.join([u'%s\n' % w for w in self]))

class PessoaForm(forms.ModelForm):
    class Meta:
        model = Pessoa
    nome = forms.CharField(max_length=100, required=True)
    sexo = forms.ChoiceField(label="Sexo", choices=SEXO_CHOICES, widget=RadioSelect(renderer=HorizRadioRenderer))
    data_nascimento = forms.DateField(label="Data de nascimento", input_formats=['%d/%m/%Y'], help_text = 'dd/mm/aaaa', required=True)
    cpf = forms.CharField(label='CPF', required=True, max_length=11)
    telefone = forms.CharField(label = 'Telefone', required = True)
    celular = forms.CharField(label = 'Celular', required = False)
    email = forms.EmailField(label = 'E-mail', required = True, max_length=100)
    igreja = forms.CharField(label='Nome da igreja que frequenta', max_length=30, required=True)
    class Media:
        js = ()

class InscricaoForm(forms.ModelForm):
    class Meta:
        model = InscricaoEvento
        exclude = ('confirmacao', 'pagamento', 'pessoa', 'valor', 'data_pagamento', 'data_inscricao', 'codigo', 'evento')
    def save(self, pessoa, evento, commit=True):
        instance = super(InscricaoForm, self).save(commit=False)
        instance.pessoa = pessoa
        instance.evento = evento
        if commit:
            instance.save()
        return instance
